package com.ssy.lingxi.purchase.controller.needplan;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.purchase.api.dto.request.*;
import com.ssy.lingxi.purchase.api.dto.response.NeedPlanListResponse;
import com.ssy.lingxi.purchase.api.dto.response.NeedPlanResponse;
import com.ssy.lingxi.purchase.entity.needplan.NeedPlanDetail;
import com.ssy.lingxi.purchase.service.needplan.NeedPlanService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * @menu 采购能力 - 需求计划管理
 * @author fhj
 * @version 2.0.0
 * @date 2021/02/26
 */
@RestController
@RequestMapping("/purchase/need/plan")
public class NeedPlanController extends BaseController {

    @Resource
    private NeedPlanService needPlanService;

    @ApiOperation(value = "内部状态")
    @GetMapping(value = "/inner")
    public Wrapper<List<Map<String, Object>>> inner() {
        return needPlanService.inner();
    }

    @ApiOperation(value = "列表（所有）")
    @GetMapping(value = "/allList")
    public Wrapper<PageData<NeedPlanListResponse>> allList(@Valid NeedPlanListRequest qo, HttpServletRequest request) {
        return needPlanService.allList(qo, getSysUser(request));
    }

    @ApiOperation(value = "列表（待新增）")
    @GetMapping(value = "/toBeAddList")
    public Wrapper<PageData<NeedPlanListResponse>> toBeAddList(@Valid NeedPlanListRequest qo, HttpServletRequest request) {
        return needPlanService.toBeAddList(qo, getSysUser(request));
    }

    @ApiOperation(value = "列表（待一级审核）")
    @GetMapping(value = "/toBeFirstExamList")
    public Wrapper<PageData<NeedPlanListResponse>> toBeFirstExamList(@Valid NeedPlanListRequest qo, HttpServletRequest request) {
        return needPlanService.toBeFirstExamList(qo, getSysUser(request));
    }

    @ApiOperation(value = "列表（待二级审核）")
    @GetMapping(value = "/toBeSecondExamList")
    public Wrapper<PageData<NeedPlanListResponse>> toBeSecondExamList(@Valid NeedPlanListRequest qo, HttpServletRequest request) {
        return needPlanService.toBeSecondExamList(qo, getSysUser(request));
    }

    @ApiOperation(value = "列表（待提交采购汇总）")
    @GetMapping(value = "/toBeSubmitList")
    public Wrapper<PageData<NeedPlanListResponse>> toBeSubmitList(@Valid NeedPlanListRequest qo, HttpServletRequest request) {
        return needPlanService.toBeSubmitList(qo, getSysUser(request));
    }

    @ApiOperation(value = "列表（待采购汇总）")
    @GetMapping(value = "/toBeCollectList")
    public Wrapper<PageData<NeedPlanListResponse>> toBeCollectList(@Valid NeedPlanListRequest qo, HttpServletRequest request) {
        return needPlanService.toBeCollectList(qo, getSysUser(request));
    }

    @ApiOperation(value = "详情")
    @GetMapping(value = "/details")
    public Wrapper<NeedPlanResponse> details(@Valid CommonIdRequest dto, HttpServletRequest request) {
        return needPlanService.details(dto, getSysUser(request));
    }

    @ApiOperation(value = "需求计划明细")
    @GetMapping(value = "/needPlanDetail")
    public Wrapper<PageData<NeedPlanDetail>> needPlanDetail(@Valid CommonIdPageRequest dto, HttpServletRequest request) {
        return needPlanService.needPlanDetail(dto, getSysUser(request));
    }

    @ApiOperation(value = "新增")
    @PostMapping(value = "/add")
    public Wrapper<Void> add(@RequestBody @Valid AddNeedPlanRequest dto, HttpServletRequest request) {
        return needPlanService.add(dto, getSysUser(request));
    }

    @ApiOperation(value = "修改")
    @PostMapping(value = "/update")
    public Wrapper<Void> update(@RequestBody @Valid UpdateNeedPlanRequest dto, HttpServletRequest request) {
        return needPlanService.update(dto, getSysUser(request));
    }

    @ApiOperation(value = "删除")
    @PostMapping(value = "/delete")
    public Wrapper<Void> delete(@RequestBody @Valid CommonIdRequest dto, HttpServletRequest request) {
        return needPlanService.delete(dto, getSysUser(request));
    }

    @ApiOperation(value = "提交审核")
    @PostMapping(value = "/submitExam")
    public Wrapper<Void> submitExam(@RequestBody @Valid CommonIdRequest dto, HttpServletRequest request) {
        return needPlanService.submitExam(dto, getSysUser(request));
    }

    @ApiOperation(value = "审核（一级）")
    @PostMapping(value = "/firstExam")
    public Wrapper<Void> firstExam(@RequestBody @Valid CommonExamRequest dto, HttpServletRequest request) {
        return needPlanService.firstExam(dto, getSysUser(request));
    }

    @ApiOperation(value = "审核（二级）")
    @PostMapping(value = "/secondExam")
    public Wrapper<Void> secondExam(@RequestBody @Valid CommonExamRequest dto, HttpServletRequest request) {
        return needPlanService.secondExam(dto, getSysUser(request));
    }

    @ApiOperation(value = "提交")
    @PostMapping(value = "/submit")
    public Wrapper<Void> submit(@RequestBody @Valid CommonIdRequest dto, HttpServletRequest request) {
        return needPlanService.submit(dto, getSysUser(request));
    }

    @ApiOperation(value = "退回")
    @PostMapping(value = "/sendBack")
    public Wrapper<Void> sendBack(@RequestBody @Valid CommonExamRequest dto, HttpServletRequest request) {
        return needPlanService.sendBack(dto, getSysUser(request));
    }

    @ApiOperation(value = "汇总")
    @PostMapping(value = "/collect")
    public Wrapper<Void> collect(@RequestBody @Valid CommonIdListRequest dto, HttpServletRequest request) {
        return needPlanService.collect(dto, getSysUser(request));
    }

    @ApiOperation(value = "导入检查")
    @PostMapping("/check")
    public Wrapper<String> check(@RequestParam(value = "file") MultipartFile file) {
        return needPlanService.check(file);
    }

    @ApiOperation(value = "导入模板")
    @PostMapping("/excel")
    public Wrapper<List<NeedPlanExcelRequest>> excel(@RequestParam(value = "file") MultipartFile file) {
        return needPlanService.excel(file);
    }
}
